package homework3;

import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        // 创建学生对象
        Student student1 = new Student("张三", 20, "男");
        Student student2 = new Student("李四", 22, "女");
        Student student3 = new Student("王五", 25, "男");

        // 创建ArrayList集合并添加学生对象
        ArrayList<Student> studentList = new ArrayList<>();
        studentList.add(student1);
        studentList.add(student2);
        studentList.add(student3);

        // 找出年龄最大的学生，并将姓名变为"小猪佩奇"
        Student maxAgeStudent = studentList.get(0);
        for (Student student : studentList) {
            if (student.getAge() > maxAgeStudent.getAge()) {
                maxAgeStudent = student;
            }
        }
        maxAgeStudent.setName("小猪佩奇");

        // 遍历集合输出对象属性信息
        for (Student student : studentList) {
            System.out.println("姓名：" + student.getName() + ", 年龄：" + student.getAge() + ", 性别：" + student.getGender());
        }
    }
}